<template>
<div class="projects">
    <query-current @search="search">
        <div slot="other" class="control-box">
            <el-button style="margin-left:10px;" type="primary" size="small">删除</el-button>
        </div>
    </query-current>
    <table-list :tableData="tableData" @flash="handleSearch" @add="handleAdd"></table-list>
    <add-dialog :addForm="addForm" @save="handleSave"></add-dialog>
</div>
</template>

<script>
import AddDialog from './AddDialog'
import TableList from './TableList'
import queryCurrent from '@/components/QueryCurrent'
export default {
    name: 'Projects',
    components: {
        AddDialog,
        TableList,
        queryCurrent
    },
    data () {
        return {
            tableData: {
                total: 0,
                pageSize: 10,
                currentPage: 1,
                list: [{
                    name: '章三1',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路',
                    user: '王小虎',
                    id: 1,
                    targList: [
                        '标签一',
                        '标签二'
                    ]
                },
                {
                    name: '章三2',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路',
                    user: '王小虎',
                    id: 2,
                    targList: [
                        '标签一',
                        '标签二'
                    ]
                },
                {
                    name: '章三3',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路',
                    user: '王小虎',
                    id: 3,
                    targList: [
                        '标签一',
                        '标签二'
                    ]
                },
                {
                    name: '章三4',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路',
                    user: '王小虎',
                    id: 4,
                    targList: [
                        '标签一',
                        '标签二'
                    ]
                },
                {
                    name: '章三5',
                    date: '2018-01-01 - 2018-01-31',
                    address: '浙江省杭州市西湖区文三西路',
                    user: '王小虎',
                    id: 5,
                    targList: [
                        '标签一',
                        '标签二'
                    ]
                }
                ]
            },
            addForm: {
                show: false,
                title: '新增',
                form: {
                    name: '',
                    listVal: '',
                    time: []
                }
            },
            queryForm: {
                name: '',
                listVal: '',
                time: []
            },
            search () {

            }
        }
    },
    created () {
        // this.init()
    },
    methods: {
        handleSave () {
            console.warn('掉用保存的接口')
            this.init()
        },
        handleSearch () {
            this.tableData.currentPage = 1
            this.init()
        },
        init () {
            const params = {
                projectId: this.$projectId,
                keyword: this.keyword,
                pageSize: this.pageSize,
                pageNum: this.currentPage
            }
            this.$post('experiment/query', params).then(res => {
                const { total, rows } = res
                this.total = total
                this.tableData = rows
            })
        },
        handleReset () {
            this.queryForm = {
                name: '',
                listVal: '',
                time: []
            }
        },
        handleAdd (isNew, item) {
            this.addForm.show = true
            if (isNew) {
                this.addForm.title = '新增'
                console.warn('新增')
            } else {
                this.addForm.title = '修改'
                console.warn('修改', item)
            }
        }
    }
}
</script>

<style lang="less">
.projects {}
</style>
